package chapter2;

/**
 * @author Hang
 * @date 2022/8/11
 * @project AutumnOffer
 * @description 面试题14 题目二
 **/
public class cuttingRope2 {
    public static void main(String[] args) {
        System.out.println(cuttingRope(120));
    }
    public static int cuttingRope(int n) {
        if(n<=3)return n-1; //默认的值
        if(n==4) return 4;
        long res = 1; //定义long类型
        while(n>4){
            res = res * 3; //有三乘三
            res = res % 1000000007; //取余
            n = n - 3; //减三
        }
        return (int)(res * n %1000000007); //最后剩下2，3，4对应相乘后取余
    }
}
